#### sqlite3 数据库初始化
import sqlite3

conn = sqlite3.connect('../sqlite3/ssh.db')
c = conn.cursor()

# 创建ssh表
# c.execute('''create table ssh
#         (ID INTEGER NOT NULL PRIMARY KEY,
#         IP varchar(28) NOT NULL,
#         PORT INT NOT NULL,
#         USER varchar(28) NOT NULL,
#         PASSWD varchar(99) NOT NULL
#     );''')

# 插入测试主机
c.execute("INSERT INTO ssh (NAME,IP,PORT,USER,PASSWD) \
      VALUES ('华为云','114.115.248.128',6666,'root','Esxi0000.')")
c.execute("INSERT INTO ssh (NAME,IP,PORT,USER,PASSWD) \
      VALUES ('测试机','192.168.101.242',22,'root','yjcloud@1234')")

# 查询数据
# cursor = c.execute("select * from ssh;")
# for row in cursor:
#     print("ID:" + row[0].__str__())
#     print("NAME:" + row[1].__str__())
#     print("IP:" + row[2].__str__())
#     print("PORT:" + row[3].__str__())
#     print("USER:" + row[4].__str__())
#     print("PASSWD:" + row[5].__str__())
#     print(" ")

# 删除数据
# deleteRow = '2';
# cursor = c.execute("delete from ssh where ID = " + deleteRow + ";")

conn.commit()
conn.close()